package com.demoo.zjsu.service.smartwebsite.zhaoban;

import com.demoo.zjsu.model.smartwebsite.PageTwo;
import com.demoo.zjsu.model.smartwebsite.PageTwoContent;
import com.demoo.zjsu.service.smartwebsite.Page;
import com.demoo.zjsu.service.smartwebsite.PageFactoryExtend;
import com.demoo.zjsu.service.smartwebsite.PageListFactoryExtend;
import com.demoo.zjsu.util.smartwebsite.WebsiteUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by jshjsh on 2016/9/9.
 * 历年招生计划
 */
@Service
public class LocaleService extends PageFactoryExtend {

    @Override
    public List<String> getTimes(Elements elements) {
        ArrayList<String> arrayList = new ArrayList<String>();
        for (Element element : elements) {
            String time = element.select("[height=18]").text();
            arrayList.add(time);
        }
        return arrayList;
    }

    @Override
    public Elements getOtherMain(Document document) {
        return document.select("[width=938]").eq(0);
    }

    @Override
    public PageTwo dealTitle(String url, String title) {
        url = url.replace("http://zhaoban.zjsu.edu.cn/html/", "").replace(".htm", "");
        return new PageTwo(title, "", url, 0);
    }

    @Override
    public void filterAgain(Elements elements) {
        elements.select("p").eq(0).remove();
    }

    @Override
    public PageTwoContent getContent(Elements elements) {
        return new PageTwoContent(elements.toString(), "");
    }

    @Override
    public Page getPage() {
        Document document = WebsiteUtil.getDocByURL("http://zhaoban.zjsu.edu.cn/listbkzn.asp?boardid=52");
        Elements elements = document.select("#table23").select("tr").eq(0);
        String url = elements.select("a").attr("abs:href");
        String category = "招生计划";
        return new Page(url, category);
    }

    @Override
    public Elements getMain(Document document) {
        return document.select("[width=607]").select("tr");
    }
}
